﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Net.Sockets;

namespace Giri.L2
{
    class Client: L1.Client
    {
        Identity identity;
        bool connected;

        public Client(TcpClient client):
            base(client)
        {
            connected = true;
        }

        ~Client()
        {
            if (connected)
                Disconnect();
        }

        public void ConnectAck(L2.Message connectMessage)
        {
            L2.Message response = new L2.Message(Message.Type.ConnectAck, identity);
            base.Send(response);
        }

        public void Disconnect()
        {
            L2.Message msg = new Message(Message.Type.Disconnect, identity);
            base.Send(msg);
        }
        public void DisconnectAck()
        {
            L2.Message msg = new Message(Message.Type.DisconnectAck, identity);
            throw new NotImplementedException();
        }

        public void SearchIdentity(Identity id)
        {
            throw new NotImplementedException();
        }

        public void FoundIdentity()
        {
            throw new NotImplementedException();
        }

        public void NotFoundIdentity()
        {
            throw new NotImplementedException();
        }

        public void RequestIdentity()
        {
            throw new NotImplementedException();
        }

        public void SendIdentity()
        {
            throw new NotImplementedException();
        }

        public void SendData(byte[] data, Identity to)
        {
            L2.Message msg = new L2.Message(Message.Type.SendData, to);
            msg.SetData(data);
            base.Send(msg);
        }

        public override L2.Message Receive()
        {
            L1.Message msg = base.Receive();
            if (msg == null)
                return null;
            return new L2.Message(msg);
        }
    }
}
